import pandas as pd
from sklearn.neighbors import KNeighborsClassifier

from sklearn.model_selection import train_test_split 
from sklearn.preprocessing import StandardScaler



 
dataIris=pd.read_csv("E:\人工智能\实验三\iris1.csv")
x11=dataIris.values[:,1:5]
y11=dataIris.values[:,5:6]



X_train, X_test, y_train, y_test = train_test_split(x11,y11, test_size = 0.7, random_state = 33)

#对训练数据集X-train和测试数据集X_test进行了规范化处理 
ss = StandardScaler()
# # 
X_train = ss.fit_transform(X_train)
# X_test = ss.transform(X_test)

# # =============================================================================
#KNN分类 
knc = KNeighborsClassifier(n_neighbors=3)#对KNN分类器进行实例化

#knc.fit(X_train, y_train)#基于训练数据得到一个分类器
knc.fit(X_train, y_train.ravel())#基于训练数据得到一个分类器
y_predict = knc.predict(X_test)#利用分类其进行预测
 
# # =============================================================================
# ## 
print ('The accuracy of K-Nearest Neighbor Classifier is: ', knc.score(X_test, y_test))